package edu.towson.cosc.cosc455.brandonmoodyProject1;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;

public class MyCompiler {
	
	static String file;
	static String fileString;
	static String fileNameNoExtension;
	
	public static void main(String[] args) throws IOException {
		//validates that file is in correct format .mkd
		file=MyLexicalAnalyzer.validateFileReadIn(args[0]);
		//attempts to create a buffered reader from the inputted fileName, if it can it continues, if not it catches FileNotFoundException
		try(BufferedReader br = new BufferedReader(new FileReader(file)))
		{
		fileString=MyLexicalAnalyzer.fileBuffer(file);
		MyLexicalAnalyzer Lexer=new MyLexicalAnalyzer();
		MyLexicalAnalyzer.visualTranslation(fileString, fileNameNoExtension);
		//processFile(Lexer, br);
		}
		catch (FileNotFoundException e)
		{
			System.out.println("The file wasn't found in current directory. Please change directories or input different file name");
		}
	}

	static void processFile(MyLexicalAnalyzer Lexer, BufferedReader br) throws IOException {
        // Reads the source file in to be compiled as a single string input
        // to check against the grammar.
            // Create a new syntax analyzer over the provided lexer.
            MySyntaxAnalyzer parser = new MySyntaxAnalyzer(Lexer);
            // Parse the given file string against the given grammar. We assume that the
            // source file is the start state.
            try {
                // Start the lexer...
            	System.out.println();
                Lexer.start(fileString);
                parser.start();
                System.out.println(fileString);
                System.out.println("COMPILATION SUCCEEDED: OUTPUT HTML FILE CREATED");
            } catch (CompilerException error) {
                // If a syntax error was found, print that the sentence does not follow the grammar.
                System.out.println("ERROR: " + error.getErrorMessage());
                System.out.println(fileString);
                System.out.println("COMPILATION FAILED: The file does not follow the BNF grammar");
            }
        }
    }
		
		//1. Check to make sure args
		//2. Check to make sure the file has an .mkd extension (Markdown language)
		//3. Initialization
		//4. Call the lexical analyzer to get the first token set
		//5. Call the start state of the parser
		
		// ... Lexer and parser does what its supposed to
		
		// 6. Call the semantic analyzer
		//7. Write the output file to html
		//8. Clean up
	//}

		
		
